# -*- makefile -*-
# vim:se ft=make:

exception.o: $(TCBOFFSET)
phys_mem.o: $(TCBOFFSET)

# Add future prerequisites somewhere among the list of libraries.
# You really should not have to add anything in the $(LD) line.

-include .kernel.sparc.lds.d

# $(1) = fiasco - variable
# $(2) = fiasco.debug - variable
# $(3) = Additional $(OBJ_X), e.g. OBJ_<unittest>
define gen_kernel_rules =
$(2): kernel.sparc.lds $$(CRT0) $$(OBJ_KERNEL) $(3) $$(JDB) $$(LIBK) $$(LIBDISASM) libdrivers.a $$(ABI) $$(LIBUART) $$(CXXLIB) $$(LIBC) libgluedriverslibc.a
	$$(LINK_MESSAGE)
	$$(VERBOSE)$$(LD) $$(LDFLAGS) $$(LD_EMULATION_FLAG) -N -defsym kernel_load_addr=$$(CONFIG_KERNEL_LOAD_ADDR) \
	  -T $$< -o $$@ $$(filter-out $$<,$$+)
	$$(call ADD_CONFIGFILE,$$@)

$(1): $(2)
	$$(LINK_MESSAGE)
	$$(VERBOSE)$$(STRIP) $$< -o $$@
	$$(VERBOSE)$$(OBJCOPY) --add-gnu-debuglink=$$< $$@
	$$(VERBOSE)chmod 755 $$@
endef

# generate $(KERNEL) rule
$(eval $(call gen_kernel_rules,$(KERNEL),$(KERNEL).debug,$(OBJ_STDWORKLOAD)))

Symbols: $(KERNEL).debug
	$(COMP_MESSAGE)
	$(VERBOSE)$(NM) $(KERNEL).debug | $(CROSS_COMPILE)c++filt | sort > $@.new
	$(VERBOSE)mv $@.new $@
	$(VERBOSE)chmod 644 $@


clean-KERNEL:
